package com.letoken.platform.repo.app.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.letoken.platform.repo.app.po.VideoDetails;
import com.letoken.platform.repo.app.po.VideoFavorite;
import com.letoken.platform.repo.app.po.VideoLike;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;

public interface VideoLikesMapper extends BaseMapper<VideoLike> {





    @Select("select t1.id,\n" +
            "       t1.url,\n" +
            "       t1.publisher,\n" +
            "       t1.poster,\n" +
            "       t1.product_id     productId,\n" +
            "       t1.description,\n" +
            "       t1.audit_status   auditStatus,\n" +
            "       t1.status         status,\n" +
            "       t1.created_at     publishedTime,\n" +
            "       t2.user_name      userName,\n" +
            "       t2.head_portrait  publisherProfilePicture,\n" +
            "       t4.ecommerce_name storeName,\n" +
            "       t3.real_price     productPrice,\n" +
            "       t3.title          productName,\n" +
            "       t3.pic            productPicture,\n" +
            "       t3.publish_status productStatus,\n" +
            "       t3.contributing   productContributing\n" +
            "from videos t1\n" +
            "         inner join video_likes t5 on t1.id = t5.video_id\n" +
            "         inner join app_user t2 on t1.publisher = t2.id\n" +
            "         left join ecommerce_product t3 on t1.product_id = t3.id and t3.delete_status = 0\n" +
            "         left join app_mall_info t4 on t1.publisher = t4.user_id\n" +
            "where t5.user_id = #{userId}\n" +
            "  and t1.status != 4\n" +
            "ORDER BY created_at DESC")
    Page<VideoDetails> page(@Param("page") Page page, @Param("userId") int userId);

    @Select("select count(id) from video_likes where user_id = #{userId}  and video_id = #{videoId}")
    Boolean liked(@Param("userId") Integer userId, @Param("videoId") Integer videoId);

    @Insert("insert ignore into video_likes(video_id, user_id, created_at) VALUE (#{videoId},#{userId},#{createdAt})")
    Integer insertIgnore( @Param("videoId") Integer videoId,@Param("userId") Integer userId,@Param("createdAt") LocalDateTime createdAt);
}
